<template>
	<view class="login" :style="{height:wh+'px'}">
		<!-- 显示上方的图片 -->
		<view class="title">
			<image src="../../static/images/login.png" mode="aspectFit" class="zzz"></image>
			<image src="../../static/images/login2.png" mode="aspectFit" class="zzz"></image>
		</view>
		<!-- 下方的表单 -->
		<view class="content">
			<uni-forms ref="logForm" :model="logFormData" :rules="rules" validate-trigger="blur">
				<uni-forms-item name="username">
					<uni-easyinput placeholder="请输入用户名" v-model="logFormData.username" />
				</uni-forms-item>
				<uni-forms-item name="password">
					<uni-easyinput type="password" placeholder="请输入密码" v-model="logFormData.password" />
				</uni-forms-item>
			</uni-forms>
			<button class="button" type="primary" @click="login()">登录</button>
		</view>
		<!-- 下方的跳转注册 -->
		<view class="register">
			<navigator url="/pages/register/register">还没有账号 ，点击注册</navigator>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		computed
	} from 'vue';
	let wh = computed(() => {
		let sh = uni.getWindowInfo().screenHeight
		let wh = uni.getWindowInfo().windowHeight
		console.log(sh)
		console.log(wh);
		return wh
	})
	const logFormData = ref({
		username: '',
		password: ''
	})
	const rules = ref({
		username: {
			rules: [{
					required: true,
					errorMessage: '请输入用户名'
				},
				{
					minLength: 3,
					maxLength: 10,
					errorMessage: '用户必须在{minLength}到{maxLength}个字符之间'
				},
				{
					pattern: '^\\w{3,10}$',
					errorMessage: '请输入3-10位数字字母和下划线作为用户名'
				}
			]
		},
		password: {
			rules: [{
					required: true,
					errorMessage: '请输入密码'
				},
				{
					pattern: '^[a-zA-Z0-9._!@#$%^&]{3,10}$',
					errorMessage: '请输入3-10位数字字母和特殊字符密码'
				}
			]
		}
	})
	let logForm = ref(null)

	function login() {
		logForm.value.validate().then((res) => {
			// 验证通过
			console.log(res)
		}).catch(err => {
			// 验证失败
			console.log(err)
		})
	}
</script>

<style scoped>
	.login {
		/* 这里添加边框,页面高度就没问题,如果不添加边框,那么页面内容就多余容器高度,显示滚动条,可以滚动 原因待查，。*/
		border: 1px solid red;
		position: relative;
	}

	/* 图片区域距离上方距离 */
	.login .title {
		margin-top: 100px;

		/* border: 1px solid red; */
	}

	/* 设置图片高度,宽度自适应 */
	.login .title image:nth-child(1) {
		height: 50px;
	}

	.login .title image:nth-child(2) {
		height: 30px;
	}

	/* 内容区域的外边距 */
	.login .content {
		margin: 10px 20px;
	}

	.title {
		margin: 0;
		padding: 0;
		width: 540rpx;
		height: 200rpx;
		margin: auto;
	}

	/* 注册链接样式 */
	.login .register {
		position: absolute;
		bottom: 20px;
		width: 100vw;
		text-align: center;
		color: #007aff;
		font-size: 20rpx;
	}
</style>